home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1174_all_outlets_are_nil.rtf < prev    next >
Text File  |  1995-06-12  |  2KB  |  51 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Ohlfs;\f2\fmodern Courier;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  I've made connections in InterfaceBuilder like I have a zillion times before.  So, why are all of my outlets nil when I run my program?\
  8. \
  9. A:  
  10. \fc1\cf1 In earlier releases, you had to provide a method to set each outlet that you declared in a new class.  For example, if your subclass had an outlet named 
  11. \b myOutlet
  12. \b0 , the source code for your subclass had to declare and implement this method:\
  13. \
  14.  
  15. \f1\fs22     - setMyOutlet:anObject\
  16.     \{\
  17.         myOutlet = anObject;\
  18.          return self;\
  19.     \}\
  20.     \
  21.  
  22. \f0\fs28 In InterfaceBuilder, the Unparse command in the Classes window's pop-up list would create these "set" methods automatically.  \
  23. \
  24. These outlet initialization methods are no longer required.  However, for backward compatibility, if an object responds to such a message, the runtime system uses them to initialize outlets.  Basically, the runtime system does this:\
  25.  
  26. \f2\fs24     \
  27.  
  28. \f1\fs22     if ([yourObject respondsTo:@selector(setMyOutlet:)])\
  29.         setMyOutlet:anObject\
  30.  
  31. \f0\fs28 \
  32. All is hunky dory, if you remember the days when these methods were required.  Now that InterfaceBuilder does not generate them automatically, it is not obvious that these method names have special meaning.  So, if you have a method name 
  33. \b setMyOutlet 
  34. \b0 you must set the outlet within that method.  If you don't initialize the outlet, then 
  35. \b myOutlet
  36. \b0  is nil at runtime.\
  37. \
  38. Overall it is best to avoid 
  39. \b setMyOutlet
  40. \b0  style method names altogether, unless you are consciously taking advantage of this "feature," and are doing
  41. \pard\tx1800\tx2160\tx2520\fc1\cf1  additional initialization within the "set" method.
  42. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1   Care must be taken, as the order in which outlets and other objects are  initialized is neither guaranteed nor predictable.
  43. \pard\tx1800\tx2160\tx2520\fc1\cf1 \
  44.  
  45. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 \
  46. QA772\
  47. \
  48. Valid for 1.0, 2.0, 3.0\
  49. \
  50.  
  51.